package com.zbkj.front.controller;

import com.zbkj.common.model.UserAiInfo;
import com.zbkj.common.model.user.User;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.UserAiInfoService;
import com.zbkj.service.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


/**
 * 用户ai信息表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/front/ai/info")
@Api(tags = "用户ai信息表")
public class UserAiInfoController {

    @Autowired
    private UserService userService;
    @Autowired
    private UserAiInfoService userAiInfoService;


    @ApiOperation(value = "添加用户ai信息")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public CommonResult<Integer> save(@RequestBody @Validated UserAiInfo userAiInfo) {
        User user = userService.getInfo();
        userAiInfo.setCreateTime(new Date())
                .setId(user.getId());
        if (userAiInfoService.save(userAiInfo)) {
            return CommonResult.success(user.getId());
        }
        return CommonResult.failed();
    }


    @ApiOperation(value = "修改用户ai信息")
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public CommonResult<String> edit(@RequestBody UserAiInfo userAiInfo) {
        if (userAiInfo == null || userAiInfo.getId() == null) {
            return CommonResult.failed("id不能为空");
        }
        userAiInfo.setUpdateTime(new Date());
        if (userAiInfoService.updateById(userAiInfo)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}



